package com.example.service.impl;

import com.example.entity.vo.CustomerWorkShopListVo;
import com.example.entity.vo.CustomerWorkShopVo;
import com.example.entity.vo.SelectCustomerCoptcDetaiVo;
import com.example.entity.vo.Taskprogressvo;
import com.example.mapper.CustomerMapper;
import com.example.service.CustomerService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;


@Service
public class CustomerServiceImpl implements CustomerService {


    @Resource
    private CustomerMapper customerMapper;
    @Override
    public List<SelectCustomerCoptcDetaiVo> selectCustomerCoptcDetail(ArrayList<String> tc004,
                                                                      String td004, String td013,
                                                                      String tc012, String td005,
                                                                      String td006, String td008,
                                                                      String td009, String td010,
                                                                      String tc003) {
        return customerMapper.selectCustomerCoptcDetail(tc004,td004,td013,tc012,td005,td006,td008,td009,td010,tc003);
    }

    @Override
    public List<CustomerWorkShopVo> selectWorkShopDetail(Integer day) {
        //保证输入的日期是负数
        day=-Math.abs(day);
        List<CustomerWorkShopVo> customerWorkShopVos = customerMapper.selectWorkShopDetail(day);
        HashMap<String,CustomerWorkShopVo> distinctWorkShopVo = new LinkedHashMap<>();
        for (CustomerWorkShopVo vo : customerWorkShopVos) {
            if ((vo.getSfcte()+vo.getUdf51())!=0){
                int d=(vo.getSfcte()/(vo.getSfcte()+vo.getUdf51()))*100;//这里计算了良品率
                vo.setYiled(String.valueOf(d));
            }
            else {
                vo.setYiled("0");
            }
            CustomerWorkShopListVo customerWorkShopListVo = new CustomerWorkShopListVo();
            BeanUtils.copyProperties(vo,customerWorkShopListVo);
            if (distinctWorkShopVo.containsKey(vo.getTe002()))
                distinctWorkShopVo.get(vo.getTe002()).getArrayList().add(customerWorkShopListVo);
            else{
                vo.setArrayList(new ArrayList<>(Collections.singletonList(customerWorkShopListVo)));
                distinctWorkShopVo.put(vo.getTe002(),vo);
            }
        }
        customerWorkShopVos.clear();
        distinctWorkShopVo.forEach((k,v)->{customerWorkShopVos.add(v);});
        return customerWorkShopVos;
    }

    @Override
    public List<Taskprogressvo> taskprogress() {
        return customerMapper.selecttaskprogress();
    }


}
